<?php 
define ('CONNECTION_STATE_CLOSED', 1);
define ('CONNECTION_STATE_OPENED', 2);

class News_Application_MySQLConnection
{
    var $Controller; 
    var $Server   = '127.0.0.1';
    var $User     = 'root';   
    var $Password = 'active';
    var $Database = 'NNTP';
    var $State    = CONNECTION_STATE_CLOSED;

    function News_Application_MySQLConnection($controller)
    {
        $this->Controller = $controller;
    }
    
    function Execute ($query)
    {
        if ($this->State != CONNECTION_STATE_OPENED)
        {
            $this->Open();
        }
        $result = MYSQL_QUERY ($query);
		return $result;
    }
    
    function Close ()
    {
        if ($this->State != CONNECTION_STATE_OPENED)
        {
            return;
        }
        MYSQL_CLOSE();   
        $this->State = CONNECTION_STATE_CLOSED;
		echo "CONNECTION TO {$this->Server}/{$this->Database} CLOSED\n================================================\n";
    }
    
    function Open ()
    {
        MYSQL_CONNECT ($this->Server, $this->User, $this->Password) or die ("Server '{$this->Server}' unreachable");
        MYSQL_SELECT_DB ($this->Database) or die ("Database '{$this->Database}' unreachable");    
        $this->State = CONNECTION_STATE_OPENED;
		echo "CONNECTION TO {$this->Server}/{$this->Database} SUCCESS\n================================================\n";
    }
}